import moment from "moment";

export const timeTrans = (
  timestamp: any,
  format: string = "YYYY-MM-DD HH:mm:ss"
) => {
  const res = moment(timestamp).format(format);
  return res;
};

export const getAge = timestamp => {
  if (!timestamp) return "-";
  const now = moment(new Date());
  const created = moment(timestamp);
  const duration = moment.duration(now.diff(created));

  const days = duration.days();
  const hours = duration.hours();
  const minutes = duration.minutes();

  return `${days > 0 ? days + "d" : ""} ${hours > 0 ? hours + "h" : ""} ${minutes > 0 ? minutes + "m" : ""}`;
};
